<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/ajax.js"></script>
    <script src="/html/js/util.js"></script>
    <title>修改页面</title>
</head>
<script>
    let id;
    window.onload = function () {
        id = getQuery("employeeId");
        init(id);
    }

    async function init(id) {
        let deptList = await ajaxGet("/dept/findAll");
        let empObj = await ajaxGet("/employee/findById", {employeeId: id});
        let str = "";
        for (let i = 0; i < deptList.length; i++) {
            let obj = deptList[i];
            str += `<option value="${obj.deptId}">${obj.deptName}</option>`;
        }
        $("deptSelect").innerHTML = str;

        $("nameSpan").innerHTML = empObj.employeeName;
        $("employeeBirthday").innerHTML = empObj.employeeBirthday;
        $("money").value = empObj.money;
        $("deptSelect").value = empObj.deptBean.deptId;
    }

    async function update() {
        let obj = {
            employeeId: id,
            deptId: $("deptSelect").value,
            money: $("money").value
        }
        let info = await ajaxGet("/employee/update", obj);
        if (info !== "ok") {
            alert("修改失败");
        }
        location.href = "/html/index.html";
    }


</script>
<body>
姓名 <span id="nameSpan"></span><br>
工资 <input type="number" id="money"><br>
生日 <span id="employeeBirthday"></span><br>
部门 <select id="deptSelect"></select><br>
<input type="button" value="点击修改" onclick="update()">

</body>
</html>